package org.example.demo3.common;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.scripting.xmltags.ForEachSqlNode;
import org.example.demo3.info.Userinfo;
import org.example.demo3.mapper.Articlemapper;
import org.example.demo3.mapper.UserMapper;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Comparator;
import java.util.List;

//优质作者算法
@Component
public class Nice_User {
    @Resource
    private Articlemapper articlemapper;
    @Resource
    private UserMapper userMapper;
    public List<Userinfo> final_nice_user(){
        List<Userinfo> list=activ_count();
        list.sort(new Comparator<Userinfo>() {
            @Override
            public int compare(Userinfo o1, Userinfo o2) {
                return o2.getActiv_count()-o1.getActiv_count();
            }
        });
        return list;
    }
    public List<Userinfo> activ_count(){
        List<Userinfo> list=userMapper.all_userid();
        for (int i=0;i<list.size();i++){
            Userinfo userinfo=articlemapper.activ_count(list.get(i).getId(),list.get(i).getId(),list.get(i).getId());
            list.get(i).setActiv_count(userinfo.getArticle_count()*4+userinfo.getType_count()*3+(int)(userinfo.getRcount()*0.3));
            list.get(i).setUsername(userinfo.getUsername());
        }
        return list;
    }
}
